﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace Twittit.WebServices
{
    // REMARQUE : vous pouvez utiliser la commande Renommer du menu Refactoriser pour changer le nom de classe "ServiceTwitt" dans le code, le fichier svc et le fichier de configuration.
    public class ServiceUser : IServiceUser
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

        public CompositeType GetDataUsingDataContract(CompositeType composite)
        {
            if (composite == null)
            {
                throw new ArgumentNullException("composite");
            }
            if (composite.BoolValue)
            {
                composite.StringValue += "Suffix";
            }
            return composite;
        }

        public Twittit.DataAccess.User GetUser(int id)
        {
            return Twittit.Business.UserService.getInstance().getUserByID(id);
        }

        public List<Twittit.DataAccess.Twit> GetTwitts(int id)
        {
            List<Twittit.DataAccess.Twit> list = ((IEnumerable<Twittit.DataAccess.Twit>)Twittit.Business.UserService.getInstance().getTwitts(id)).Take(30).ToList();
            return list;
        }

        public int CountUserPosts(int id)
        {
            return Twittit.Business.UserService.getInstance().countUserPosts(id);
        }

        public List<Twittit.DataAccess.Twit> GetUserTwitts(int id)
        {
           
            return ((IEnumerable<Twittit.DataAccess.Twit>) Twittit.Business.UserService.getInstance().getUserTwitts(id)).Take(30).ToList();
        }
        
        public Twittit.DataAccess.User GetUserByUsername(string username)
        {
            return Twittit.Business.UserService.getInstance().getUserByUsername(username);
        }

        public Boolean CheckPassword(string username, string password)
        {
            return Twittit.Business.UserService.getInstance().checkPassword(username,password);
        }

        public List<Twittit.DataAccess.User> SuggestUsers(int id)
        {

            return ((IEnumerable<Twittit.DataAccess.User>)Twittit.Business.UserService.getInstance().suggestUsers(id)).Take(10).ToList();
        }

        public Twittit.DataAccess.User EditUser(Twittit.DataAccess.User u, String name, String twittit, String mail, String website, String localisation, String about, byte userConfirm, bool twitter, int UserId = -1)
        {
            return Twittit.Business.UserService.getInstance().editUser(u, name, twittit, mail, website, localisation, about, userConfirm, twitter, UserId);
        }
        
        public int RemoveTwitt(int twittId, int userId){
            return Twittit.Business.TwittService.getInstance().removeTwitt(twittId, userId);
        }
    }
}
